package com.hetwen.remoteboot.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class DBOpenHelper extends SQLiteOpenHelper {
	
	public static final String DBNAME = "remoteboot.db";
	public static final String TBNAME = "mac_addresses";
	
	private static SQLiteOpenHelper helper;
	
	public static SQLiteOpenHelper getInstance(Context context){
		if(helper == null){
			helper = new DBOpenHelper(context);
		}
		return helper;
	}
	
	private DBOpenHelper(Context context){
		this(context, DBNAME, null, 1);
	}
	
	private DBOpenHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		
		String sql = "CREATE TABLE "+TBNAME+" " +
				"(" +
				"id INTEGER PRIMARY KEY AUTOINCREMENT," +
				"name VARCHAR(50) NOT NULL," +
				"mac CHAR(12) NOT NULL" +
				");";
		db.execSQL(sql);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

}
